<extend name="Base/common" />
<block name="body">
  <style text='text/css'>
.image_material{
    border: 1px dashed #ddd;
    width: 308px;
    height: 196px;
     background: #eee;
    text-align: center;
    color: #333;
    display: block;
    float: left;
    margin-left:50px;
   position:relative;
}
.image_material .select_image{line-height: 196px; display:block; height:200px;}
.image_material .delete{ position:absolute; bottom:3px; left:3px; display:none}
</style>
  <!-- 标签页导航 -->
  <div class="span9 page_message">
    <section id="contents">
      <include file="Addons/_nav" />
      <div class="tab-content"> 
        <!-- 表单 -->
        <php> $post_url || $post_url = U('edit?model='.$model['id'], $get_param);</php>
        <form id="form" action="{$post_url}" method="post" class="form-horizontal form-center">
          
              <volist name="fields" id="field">
                <if condition="$field['is_show'] == 4">
                  <input type="hidden" class="text" name="{$field.name}" value="{$data[$field['name']]}">
                </if>
                <if condition="$field['is_show'] == 1 || $field['is_show'] == 3 || ($field['is_show'] == 5 && I($field['name']) )">
                  <div class="form-item cf toggle-{$field.name}">
                    <label class="item-label">
                    <notempty name="field.is_must"><span class="need_flag">*</span></notempty>
                    {$field['title']}
                    <if condition="$field['name'] eq 'content'" >
                     <a href='javascript:;' id='getText'  onClick="selectText();" style="display: inline;border: 1px solid #DFE2EC;padding: 8px;margin-left: 20px;border-radius: 5px;background-color: #EEEFF1;color: #A6A8AD;">选择文本素材</a>
                   	 <elseif condition="$field['name'] eq 'image_id'"/>
                   	   
                    </if>
                    <span class="check-tips">
                      <notempty name="field['remark']">（{$field['remark']}）</notempty>
                      </span></label>
                    <div class="controls">
                      <switch name="field.type">
                        <case value="num">
                          <input type="number" class="text" name="{$field.name}" value="{$data[$field['name']]}">
                        </case>
                        <case value="string">
                          <input type="text" class="text input-large" name="{$field.name}" value="{$data[$field['name']]}">
                        </case>
                        <case value="textarea">
                          <label class="textarea input-large">
                            <textarea name="{$field.name}">{$data[$field['name']]}</textarea>
                          </label>
                        </case>
                        <case value="datetime">
                          <input type="datetime" name="{$field.name}" class="text time" value="{$data[$field['name']]|time_format}" placeholder="请选择时间" />
                        </case>
                        <case value="date">
                          <input type="datetime" name="{$field.name}" class="text date" value="{$data[$field['name']]|time_format='Y-m-d'}" placeholder="请选择时间" />
                        </case>                        
                        <case value="bool">
                          <volist name=":parse_field_attr($field['extra'])" id="vo">
                          	<div class="check-item">
							<!--[if !IE]><!-->  
								  <input type="radio" class="regular-radio toggle-data" value="{$key}" id="{$field.name}_{$key}" name="{$field.name}" toggle-data="{$vo|get_hide_attr}"
								  <eq name="data[$field['name']]" value="$key">checked="checked"</eq> />
								  <label for="{$field.name}_{$key}"></label>{$vo|clean_hide_attr} 
							  <!--<![endif]-->
							   <!--[if IE]>
							       <input type="radio" value="{$key}" 
								   id="{$field.name}_{$key}" name="{$field.name}" class="toggle-data" toggle-data="{$vo|get_hide_attr}"
								  <eq name="data[$field['name']]" value="$key">checked="checked"</eq>/> 
								  <label for="{$field.name}_{$key}"></label>{$vo|clean_hide_attr}
							   <![endif]-->
                             </div>
                          </volist>
                        </case>
                        <case value="select">
                          <select name="{$field.name}">
                            <volist name=":parse_field_attr($field['extra'])" id="vo"> <option value="{$key}" class="toggle-data" toggle-data="{$vo|get_hide_attr}"
                              <eq name="data[$field['name']]" value="$key">selected</eq>
                              >{$vo|clean_hide_attr}
                              </option>
                            </volist>
                          </select>
                        </case>
                        <case value="cascade">
                        <div id="cascade_{$field.name}"></div>
                        {:hook('cascade', array('name'=>$field['name'],'value'=>$data[$field['name']],'extra'=>$field['extra']))}
                        </case>                      
                        <case value="dynamic_select">
                        <div id="dynamic_select_{$field.name}"></div>
                        {:hook('dynamic_select', array('name'=>$field['name'],'value'=>$data[$field['name']],'extra'=>$field['extra']))}
                        </case>   
                        <case value="news">
                        <div id="news_{$field.name}"></div>
                        {:hook('news', array('name'=>$field['name'],'value'=>$data[$field['name']],'extra'=>$field['extra']))}
                        </case> 
                        <case value="image">
                        <div id="image_{$field.name}"></div>
                        {:hook('image', array('name'=>$field['name'],'value'=>$data[$field['name']],'extra'=>$field['extra']))}
                        
                        <case value="radio">
                          <volist name=":parse_field_attr($field['extra'])" id="vo">
                          	<div class="check-item">
							<!--[if !IE]><!-->  
								  <input type="radio" class="regular-radio toggle-data" value="{$key}" id="{$field.name}_{$key}" name="{$field.name}" toggle-data="{$vo|get_hide_attr}"
								  <eq name="data[$field['name']]" value="$key">checked="checked"</eq> />
								  <label for="{$field.name}_{$key}"></label>{$vo|clean_hide_attr} 
							  <!--<![endif]-->
							   <!--[if IE]>
							       <input type="radio" value="{$key}" 
								   id="{$field.name}_{$key}" name="{$field.name}" class="toggle-data" toggle-data="{$vo|get_hide_attr}"
								  <eq name="data[$field['name']]" value="$key">checked="checked"</eq>/> 
								  <label for="{$field.name}_{$key}"></label>{$vo|clean_hide_attr}
							   <![endif]-->
                             </div>
                          </volist>
                        </case>
                        <case value="checkbox">
                          <volist name=":parse_field_attr($field['extra'])" id="vo">
                          	<div class="check-item">
                              <input type="checkbox" class="regular-checkbox toggle-data" value="{$key}" id="{$field.name}_{$key}" name="{$field.name}[]" toggle-data="{$vo|get_hide_attr}"
                              <in name="key" value="$data[$field['name']]" >checked="checked"</in> >
                              <label for="{$field.name}_{$key}"></label>{$vo|clean_hide_attr} 
                             </div>
                          </volist>
                        </case>
                        <case value="editor">
                          <label class="textarea">
                            <textarea name="{$field.name}" style="width:405px; height:100px;">{$data[$field['name']]}</textarea>
                            {:hook('adminArticleEdit', array('name'=>$field['name'],'value'=>$data[$field['name']]))} </label>
                        </case>
                        <case value="picture">
                          <div class="controls uploadrow2" title="点击修改图片" rel="{$field.name}" style="float: left;">
                            <input type="file" id="upload_picture_{$field.name}">
                            <input type="hidden" name="{$field.name}" id="cover_id_{$field.name}" value="{$data[$field['name']]}"/>
                            <div class="upload-img-box">
                              <notempty name="data[$field['name']]">
                                <div class="upload-pre-item2"><img width="100" height="100" src="{$data[$field['name']]|get_cover_url}"/></div>
                                <em class="edit_img_icon">&nbsp;</em>
                              </notempty>

                            </div>
                            
                          </div>
                           
                            <div class='image_material' id='image_material'>
                              <input type="hidden" name="image_material" id="cover_id_image" value="{$data.image_material}"/>
                              <a class="select_image" href="javascript:;"  onClick="$.WeiPHP.openSelectAppMsg('{:U('/Home/Material/picture_data')}',selectImageCallback,'选择图片素材')">从素材库选择图片</a>
                              <div class="image_wrap"></div>
                              <a class="delete" href="javascript:;" style="left: 15px;">删除</a>
                              </div>
                        </case>
                        <case value="mult_picture">
                            <div class="mult_imgs">
                                <div class="upload-img-view" id='mutl_picture_{$field.name}'>
                                  <notempty name="data[$field['name']]">
                                  	<volist name="data[$field['name']]" id="vo">
                                    <div class="upload-pre-item22">
                                    <img width="100" height="100" src="{$vo|get_cover_url}"/>
                                    <input type="hidden" name="{$field.name}[]" value="{$vo}"/>
                                    <em>&nbsp;</em>
                                    </div>
                                    </volist>
                                  </notempty>
                                </div>
                                <div class="controls uploadrow2 mult" title="点击上传图片" rel="{$field.name}">
                                  <input type="file" id="upload_picture_{$field.name}">
                                </div>
                            </div>
                        </case>
                        <case value="file">
                          <div class="controls upload_file" rel="{$field.name}">
                            <input type="file" id="upload_file_{$field.name}">
                            <input type="hidden" name="{$field.name}" value="{$data[$field['name']]}"/>
                            <div class="upload-img-box">
                              <present name="data[$field['name']]">
                                <div class="upload-pre-file"><span class="upload_icon_all"></span>{$data[$field['name']]|get_table_field=###,'id','name','File'}</div>
                              </present>
                            </div>
                          </div>
                          
                        </case>
                        <case value="user">
                        <div class="controls">
                            <div id="userList" class="common_add_list fl">
                                <notempty name="data[$field['name']]">
                                    <div class="item" onClick="$.WeiPHP.selectSingleUser('{:addons_url('UserCenter://UserCenter/lists')}','{$field.name}');">
                                        <php>
                                            $userInfo = getUserInfo($data[$field['name']]);
                                            
                                        </php>
                                        <img src="{$userInfo['headimgurl']}"/><br/><span>{$userInfo['nickname']}</span>
                                        <input type="hidden" name="{$field.name}'" value="{$data[$field['name']]}"/>
                                        <span class="name">{$userInfo['nickname']}</span>
                                    </div>
                                <else/>
                                <a href="javascript:;" class="common_add_btn fl" onClick="$.WeiPHP.selectSingleUser('{:addons_url('UserCenter://UserCenter/lists')}','{$field.name}');"></a>
                                </notempty>
                           </div>
                        </div>
                      </case>
                      <case value="users">
                        <div class="controls">
                            <div id="userList" class="common_add_list fl">
                                <notempty name="data[$field['name']]">
                                	<php>
                                            $userIds = explode(',',$data[$field['name']]);
                                    </php>
                                	<volist name="userIds" id="uid">
                                    <php>
                                            $userInfo = getUserInfo($uid);
                                            
                                    </php>
                                    <div class="item" onClick="$.WeiPHP.selectSingleUser('{:addons_url('UserCenter://UserCenter/lists')}','{$field.name}');">
                                        <php>
                                            $userInfo = getUserInfo($data[$field['name']]);
                                            
                                        </php>
                                        <img src="{$userInfo['headimgurl']}"/><br/><span>{$userInfo['nickname']}</span>
                                        <input type="hidden" name="{$field.name}'[]" value="{$data[$field['name']]}"/>
                                        <span class="name">{$userInfo['nickname']}</span>
                                    </div>
                                    </volist>
                                </notempty>
                               <a href="javascript:;" class="common_add_btn fl" onClick="$.WeiPHP.selectMutiUser('{:addons_url('UserCenter://UserCenter/lists')}',9,'{$field.name}');"></a>
                           </div>
                        </div>
                      </case>
                      <case value="admin">
                        <div class="controls">
                            <div id="userList" class="common_add_list fl">
                                <notempty name="data[$field['name']]">
                                    <div class="item" onClick="$.WeiPHP.selectSingleUser('{:addons_url('UserCenter://UserCenter/admin_lists')}','{$field.name}');">
                                        <php>
                                            $userInfo = getUserInfo($data[$field['name']]);
                                            
                                        </php>
                                        <img src="{$userInfo['headimgurl']}"/><br/><span>{$userInfo['nickname']}</span>
                                        <input type="hidden" name="{$field.name}'" value="{$data[$field['name']]}"/>
                                        <span class="name">{$userInfo['nickname']}</span>
                                    </div>
                                <else/>
                                <a href="javascript:;" class="common_add_btn fl" onClick="$.WeiPHP.selectSingleUser('{:addons_url('UserCenter://UserCenter/admin_lists')}','{$field.name}');"></a>
                                </notempty>
                           </div>
                        </div>
                      </case>                      
                        <default/>
                        <input type="text" class="text input-large" name="{$field.name}" value="{$data[$field['name']]}">
                      </switch>
                    </div>
                  </div>
                </if>
              </volist>
           
        </div>
        <div class="form-item form_bh" style="text-align:center">
            <notempty name="data.id"><input type="hidden" name="id" value="{$data.id}"></notempty>
            <button class="btn submit-btn ajax-post" id="submit" type="submit" target-form="form-horizontal">{$submit_name|default='确 定'}</button>
          </div>
      </form>
      </div>
    </section>
  </div>
</block>
<block name="script">
  <link href="__STATIC__/datetimepicker/css/datetimepicker.css?v={:SITE_VERSION}" rel="stylesheet" type="text/css">
  <php>if(C('COLOR_STYLE')=='blue_color') echo '
    <link href="__STATIC__/datetimepicker/css/datetimepicker_blue.css?v={:SITE_VERSION}" rel="stylesheet" type="text/css">
    ';</php>
  <link href="__STATIC__/datetimepicker/css/dropdown.css?v={:SITE_VERSION}" rel="stylesheet" type="text/css">
  <script type="text/javascript" src="__STATIC__/datetimepicker/js/bootstrap-datetimepicker.min.js"></script> 
  <script type="text/javascript" src="__STATIC__/datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js?v={:SITE_VERSION}" charset="UTF-8"></script> 
  <script type="text/javascript">
  $(function(){
	 var str_image='<div class="appmsg_item"><div class="main_img"><img src="{$data.cover_url}" width="200px" height="200px"/></div></div><div class="hover_area"></div>';
	 var material_image="{$data.image_material}";
	 if(material_image != 0){
		 $('.image_wrap').html(str_image).show();
		 $('.select_image').hide();
		 $('.image_material .delete').show();
	 }
	initUploadImg({width:100,height:100,callback:function(){
    $('.image_wrap').html('').hide();
    $('.select_image').show();
    $('.image_material .delete').hide();
    $('input[name="image_material"]').val(0);
  }});
	initUploadFile();
   
   $('.time').datetimepicker({
        format: 'yyyy-mm-dd hh:ii',
        language:"zh-CN",
        minView:0,
        autoclose:true
    });
    $('.date').datetimepicker({
        format: 'yyyy-mm-dd',
        language:"zh-CN",
        minView:2,
        autoclose:true
    });	
    showTab();
	
	$('.toggle-data').each(function(){
		var data = $(this).attr('toggle-data');
		if(data=='') return true;		
		
	     if($(this).is(":selected") || $(this).is(":checked")){
			 change_event(this)
		 }
	});
	
	$('.toggle-data').bind("click",function(){ change_event(this) });

  $('.image_material .delete').click(function(){
    $('.image_wrap').html('').hide();
    $('.select_image').show();
    $('.image_material .delete').hide();
    $('input[name="image_material"]').val(0);
  })


});
  function selectImageCallback(_this){
    $('.image_wrap').html($(_this).html()).show();
    $('.select_image').hide();
    $('.image_material .delete').show();
    $('input[name="image_material"]').val($(_this).data('id'));
    $("input[name='image_id']").val(0);
    $('.upload-pre-item2').hide();
    $.Dialog.close();
  }
  function selectText(){
		$.WeiPHP.openSelectLists("{:U('Material/text_lists')}",1,'选择素材',function(data){
			if(data && data.length>0){
				for(var i=0;i<data.length;i++){
					var id=data[i]['id'];
					if(id){
						$.post("{:U('Material/get_content_by_id')}",{'id':id},function(d){
							$("textarea[name='content']").text(d);
						})
					}
				}
			}
		})
	}


</script> 
</block>
